

matrix margins = r(margeff) // Save marginal effects as variables
svmat margins, names(col)
matrix at = r(at)

gen x = _n - 51 // This saves a kernel density estimate showing the number of observations at various levels of Z
replace x = . if x > 80
kdensity adviceCand if sample == 1, gen(d) at(x) nodraw 


gen zero = 0 // The following code is for the graph


* Graph
sum d
local yrange2 = `r(max)' * 6
graph twoway area d x if x <= 0, fcolor(red*.9) lcolor(red*.9) fintensity(100) yaxis(2) ///
	||  area d x if x >= 40, fcolor(green*.9) lcolor(green*.9) fintensity(100) yaxis(2) ///
	||  area d x if inrange(x,0,40), fcolor(gold*.9) lcolor(gold*.9) fintensity(100) yaxis(2) ///
    ||  rarea CI_l CI_u xlevel if inrange(xlevel,-45,80), fcolor(gs14%100) lcolor(gs14%100) fintensity(100) ///
	||  line marg xlevel if inrange(xlevel,-45,80), clcolor(black) clpattern(solid) lwidth(medthick) ///
	||  line zero xlevel if inrange(xlevel,-45,80), clcolor(black) clpattern(solid) lwidth(thin) ///
		, xlabel(-50(25)75, nogrid tlcolor(black)) ///
		ylabel(-1(0.5)1, axis(1) nogrid angle(horizontal) tlcolor(black)) ///
        ylabel(, axis(2) nogrid noticks nolabels) ///
        yscale(range(-1.1 1.1) noline alt) yscale(range(0 `yrange2') noline alt axis(2)) xscale(noline) ///
		yline(0, lcolor(black) lwidth(thin) lpattern(solid)) ///
        xtitle("Candidate-level VAA advice (continuous)", margin(top)) ///
        ytitle("Marginal effect on PTV for candidate", margin(medsmall)) ///
        ytitle("" , axis(2) size(4) margin(zero)) ///
        ysca(axis(2) titlegap(4)) ///
		xsize(6) ysize(5) ///
		title("$title", margin(bottom) size(medlarge)) ///
		legend(off) scale(*1) scheme(Cleanplots) graphregion(fcolor(white) ilcolor(white) lcolor(white)) bgcolor(white)	saving($name, replace) nodraw